#include <QRegExpValidator>
#include "sgmtation.h"
#include "ui_sgmtation.h"

Sgmtation::Sgmtation(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Sgmtation)
{
    ui->setupUi(this);
    setWindowFlags(Qt::Tool| Qt::WindowStaysOnTopHint);
    ui->lineEdit->setValidator(new QRegExpValidator(QRegExp("1?[0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]")));
    ui->lineEdit_2->setValidator(new QRegExpValidator(QRegExp("1?[0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]")));
    ui->lineEdit_3->setValidator(new QRegExpValidator(QRegExp("1?[0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]")));
    ui->lineEdit_4->setValidator(new QRegExpValidator(QRegExp("1?[0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5]")));
}

Sgmtation::~Sgmtation()
{
    delete ui;
}

void Sgmtation::on_horizontalSlider_sliderMoved(int position)
{
    QString num=QString("%1").arg(position);
    ui->lineEdit->setText(num);
}

void Sgmtation::on_pushButton_2_clicked()
{
    this->close();
}

void Sgmtation::on_pushButton_clicked()
{
    emit sendData(ui->lineEdit->text().toInt(),ui->lineEdit_2->text().toInt(),ui->lineEdit_3->text().toInt(),ui->lineEdit_4->text().toInt());
    this->close();
}


void Sgmtation::on_horizontalSlider_valueChanged(int value)
{
    QString num=QString("%1").arg(value);
    ui->lineEdit->setText(num);
}

void Sgmtation::on_lineEdit_4_editingFinished()
{
    ui->label_7->clear();
    QPalette palette;
    palette.setColor(QPalette::Window, QColor(ui->lineEdit_2->text().toInt(), ui->lineEdit_3->text().toInt(), ui->lineEdit_4->text().toInt()));
    ui->label_7->setAutoFillBackground(true);
    ui->label_7->setPalette(palette);
}

void Sgmtation::on_lineEdit_2_editingFinished()
{
    ui->label_7->clear();
    QPalette palette;
    palette.setColor(QPalette::Window, QColor(ui->lineEdit_2->text().toInt(), ui->lineEdit_3->text().toInt(), ui->lineEdit_4->text().toInt()));
    ui->label_7->setAutoFillBackground(true);
    ui->label_7->setPalette(palette);
}

void Sgmtation::on_lineEdit_3_editingFinished()
{
    ui->label_7->clear();
    QPalette palette;
    palette.setColor(QPalette::Window, QColor(ui->lineEdit_2->text().toInt(), ui->lineEdit_3->text().toInt(), ui->lineEdit_4->text().toInt()));
    ui->label_7->setAutoFillBackground(true);
    ui->label_7->setPalette(palette);
}

void Sgmtation::on_lineEdit_2_textChanged(const QString &arg1)
{
    ui->label_7->clear();
    QPalette palette;
    palette.setColor(QPalette::Window, QColor(ui->lineEdit_2->text().toInt(), ui->lineEdit_3->text().toInt(), ui->lineEdit_4->text().toInt()));
    ui->label_7->setAutoFillBackground(true);
    ui->label_7->setPalette(palette);
}

void Sgmtation::on_lineEdit_3_textChanged(const QString &arg1)
{
    ui->label_7->clear();
    QPalette palette;
    palette.setColor(QPalette::Window, QColor(ui->lineEdit_2->text().toInt(), ui->lineEdit_3->text().toInt(), ui->lineEdit_4->text().toInt()));
    ui->label_7->setAutoFillBackground(true);
    ui->label_7->setPalette(palette);
}

void Sgmtation::on_lineEdit_4_textChanged(const QString &arg1)
{
    ui->label_7->clear();
    QPalette palette;
    palette.setColor(QPalette::Window, QColor(ui->lineEdit_2->text().toInt(), ui->lineEdit_3->text().toInt(), ui->lineEdit_4->text().toInt()));
    ui->label_7->setAutoFillBackground(true);
    ui->label_7->setPalette(palette);
}
